home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / uwpc201.zip / UW-SRC.ZIP / SCREEN.CPP < prev    next >
C/C++ Source or Header  |  1991-08-01  |  9KB  |  312 lines

  1. //-------------------------------------------------------------------------
  2. //
  3. // SCREEN.CPP - Direct screen accessing routines for textual displays.
  4. // 
  5. //  This file is part of UW/PC - a multi-window comms package for the PC.
  6. //  Copyright (C) 1990-1991  Rhys Weatherley
  7. //
  8. //  This program is free software; you can redistribute it and/or modify
  9. //  it under the terms of the GNU General Public License as published by
  10. //  the Free Software Foundation; either version 1, or (at your option)
  11. //  any later version.
  12. //
  13. //  This program is distributed in the hope that it will be useful,
  14. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. //  GNU General Public License for more details.
  17. //
  18. //  You should have received a copy of the GNU General Public License
  19. //  along with this program; if not, write to the Free Software
  20. //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. //
  22. // Revision History:
  23. // ================
  24. //
  25. //  Version  DD/MM/YY  By  Description
  26. //  -------  --------  --  --------------------------------------
  27. //    1.0    23/03/91  RW  Original Version of SCREEN.CPP
  28. //    1.1    26/05/91  RW  Add command-line to "jumpdos".
  29. //
  30. // You may contact the author by:
  31. // =============================
  32. //
  33. //  e-mail: rhys@cs.uq.oz.au
  34. //    mail: Rhys Weatherley
  35. //          5 Horizon Drive
  36. //          Jamboree Heights
  37. //          Queensland 4074
  38. //        Australia
  39. //
  40. //-------------------------------------------------------------------------
  41.  
  42. #include "screen.h"        // Declarations for this module.
  43. #include "config.h"        // Configuration declarations.
  44. #include "mouse.h"        // Mouse handling routines.
  45. #include <dos.h>        // Turbo C++ DOS/BIOS/hardware routines.
  46. #include <conio.h>        // Turbo C++ console routines.
  47. #include <mem.h>        // Memory manipulation routines.
  48. #include <stdlib.h>        // "system" is defined here.
  49.  
  50. #pragma    warn    -par        // Turn off annoying warnings.
  51.  
  52. //
  53. // Define the primary hardware screen handling object.
  54. //
  55. ScreenClass    HardwareScreen;
  56.  
  57. //
  58. // Define the bits in the "ScreenClass::flags" attribute.
  59. //
  60. enum   ScreenFlags {
  61.     FLAG_MDA    = 1,        // MDA screen mode.
  62.     FLAG_SNOW    = 2,        // Snow checking is enabled.
  63.     FLAG_COLOR    = 4        // Screen mode is colour.
  64. };
  65.  
  66. // Initialise the hardware screen.  Returns non-zero
  67. // if OK, or zero if there is not enough memory.
  68. int    ScreenClass::init (int color,int large)
  69. {
  70.   struct text_info ti;
  71.   static unsigned char monoattrs[NUM_ATTRS] = {0x07,0x70,0x0F,0x70,0x07};
  72.   static unsigned char colrattrs[NUM_ATTRS] = {0x1F,0x71,0x1E,0x4E,0x41};
  73.   int temp;
  74.   gettextinfo (&ti);
  75.   oldattr = ti.attribute;
  76.   dialogenabled = 0;        // Disable the dialog box.
  77.   if (ti.currmode == 7)
  78.     {
  79.       mode = 7;
  80.       flags = FLAG_MDA;
  81.       screenram = (unsigned far *)0xB0000000L;
  82.     } /* then */
  83.   else
  84.     {
  85.       if (!color && (ti.currmode == 0 || ti.currmode == 2))
  86.         {
  87.           mode = 2;
  88.       flags = FLAG_SNOW;
  89.         } /* then */
  90.        else
  91.         {
  92.           mode = 3;
  93.       flags = FLAG_SNOW | FLAG_COLOR;
  94.         } /* else */
  95.       screenram = (unsigned far *)0xB8000000L;
  96.     } /* else */
  97.   if (!iscolor ())
  98.     memcpy (attributes,monoattrs,NUM_ATTRS);
  99.    else
  100.     memcpy (attributes,colrattrs,NUM_ATTRS);
  101.   for (temp = 0;temp < NUM_ATTRS;++temp)
  102.     {
  103.       // Override the default attribute scheme //
  104.       if (UWConfig.NewAttrs[temp])
  105.         attributes[temp] = UWConfig.NewAttrs[temp];
  106.     }
  107.   textmode (mode);
  108.   shape ((CursorShapes)UWConfig.CursorSize);
  109.   width = 80;
  110.   height = 25;
  111.   delay (10);        // Initialise Turbo C++'s delay timer.
  112.   return (1);
  113. } // ScreenClass::init //
  114.  
  115. // Terminate the hardware screen.
  116. void    ScreenClass::term (void)
  117. {
  118.   shape (CURS_UNDERLINE);
  119.   textattr (oldattr);
  120.   clrscr ();
  121.   gotoxy (1,1);
  122. } // ScreenClass::term //
  123.  
  124. // Test to see if a colour mode is in effect.
  125. int    ScreenClass::iscolor (void)
  126. {
  127.   return ((flags & FLAG_COLOR) != 0);
  128. } // ScreenClass::iscolor //
  129.  
  130. // Set the position of the hardware screen cursor.
  131. void    ScreenClass::cursor (int x,int y)
  132. {
  133.   union REGS regs;
  134.   regs.h.ah = 2;
  135.   regs.h.bh = 0;
  136.   regs.h.dl = x;
  137.   regs.h.dh = y;
  138.   int86 (0x10,®s,®s);
  139. } // ScreenClass::cursor //
  140.  
  141. // Set the shape of the hardware cursor.
  142. void    ScreenClass::shape (CursorShapes curs)
  143. {
  144.   union REGS regs;
  145.   static int monoshapes[] = {0x200C,0x0B0C,0x070C,0x000C};
  146.   static int colrshapes[] = {0x2007,0x0607,0x0407,0x0007};
  147.   regs.h.ah = 1;
  148.   if (flags & FLAG_MDA)
  149.     regs.x.cx = monoshapes[curs];
  150.    else
  151.     regs.x.cx = colrshapes[curs];
  152.   int86 (0x10,®s,®s);
  153. } // ScreenClass::shape //
  154.  
  155. // Ring the hardware terminal bell.
  156. void    ScreenClass::bell (void)
  157. {
  158.   union REGS regs;
  159.   if (UWConfig.BeepEnable)
  160.     {
  161.       regs.x.ax = 0x0E07;
  162.       regs.x.bx = 0;
  163.       int86 (0x10,®s,®s);    // Call video BIOS to ring the bell.
  164.     }
  165. } // ScreenClass::bell //
  166.  
  167. // Mark an area for the dialog box.
  168. void    ScreenClass::mark (int x1,int y1,int x2,int y2)
  169. {
  170.   dialogenabled = 0;
  171.   dlgx1 = x1;
  172.   dlgy1 = y1;
  173.   dlgx2 = x2;
  174.   dlgy2 = y2;
  175. } // ScreenClass::mark //
  176.  
  177. // Draw a single pair on the screen, waiting for snow //
  178. static    void    drawsnow (unsigned far *addr,unsigned pair)
  179. {
  180.   _ES = FP_SEG(addr);
  181.   _DI = FP_OFF(addr);
  182.   _BX = pair;
  183.   /* Assembly code here is:
  184.  
  185.         mov  dx,3dah
  186.      loop1: in   al,dx
  187.         test al,1
  188.         jnz  loop1
  189.         cli
  190.      loop2: in   al,dx
  191.         test al,1
  192.         jz   loop2
  193.         mov  es:[di],bx
  194.         sti
  195.   */
  196.   __emit__ (0xBA,0xDA,0x03,0xEC,0xA8,0x01,
  197.         0x75,0xFB,0xFA,0xEC,0xA8,0x01,
  198.         0x74,0xFB,0x26,0x89,0x1D,0xFB);
  199. } // drawsnow //
  200.  
  201. // Draw a character/attribute pair on the screen.
  202. void    ScreenClass::draw (int x,int y,unsigned pair,int dialog)
  203. {
  204.   if (dialogenabled && !dialog)
  205.     {
  206.       if (y >= dlgy1 && y <= dlgy2 && x >= dlgx1 && x <= dlgx2)
  207.         return;        // Ignore when in the area of the dialog box.
  208.     }
  209.   HideMouse ();        // Turn off mouse if necessary.
  210.   if (flags & FLAG_SNOW)
  211.     drawsnow (screenram + x + (y * width),pair);
  212.    else
  213.     screenram[x + (y * width)] = pair;
  214.   ShowMouse ();        // Turn the mouse back on.
  215. } // ScreenClass::draw //
  216.  
  217. // Draw a lines of character/attribute pairs on the screen.
  218. void    ScreenClass::line (int x,int y,unsigned *pairs,int numpairs,
  219.                 int dialog)
  220. {
  221.   unsigned far *screen;
  222.   screen = screenram + x + (y * width);
  223.   if (dialogenabled && !dialog)
  224.     {
  225.       if (y >= dlgy1 && y <= dlgy2 && x <= dlgx2)
  226.         {
  227.       // Send the line direct, but ignore where it crosses dialog box.
  228.       HideMouse ();
  229.       while (numpairs-- > 0)
  230.         {
  231.           if (x < dlgx1 || x > dlgx2)
  232.             {
  233.                   if (flags & FLAG_SNOW)
  234.                     drawsnow (screen++,*pairs);
  235.                    else
  236.                     *screen++ = *pairs;
  237.         }
  238.           ++x;
  239.           ++pairs;
  240.         }
  241.       ShowMouse ();
  242.       return;        // Ignore the rest of this function.
  243.     }
  244.     }
  245.   HideMouse ();
  246.   if (flags & FLAG_SNOW)
  247.     {
  248.       while (numpairs-- > 0)
  249.         drawsnow (screen++,*pairs++);
  250.     }
  251.    else
  252.     {
  253.       while (numpairs-- > 0)
  254.         *screen++ = *pairs++;
  255.     }
  256.   ShowMouse ();
  257. } // ScreenClass::line //
  258.  
  259. // Scroll an area of the screen a number of lines.
  260. void    ScreenClass::scroll (int x1,int y1,int x2,int y2,int lines,
  261.                   unsigned char attr)
  262. {
  263.   union REGS regs;
  264.   if (lines >= 0)
  265.     regs.x.ax = 0x600 + lines;
  266.    else
  267.     regs.x.ax = 0x700 - lines;
  268.   regs.h.bh = attr;
  269.   regs.h.cl = x1;
  270.   regs.h.ch = y1;
  271.   regs.h.dl = x2;
  272.   regs.h.dh = y2;
  273.   HideMouse ();
  274.   int86 (0x10,®s,®s);
  275.   ShowMouse ();
  276. } // ScreenClass::scroll //
  277.  
  278. // Clear the screen and shell out to DOS.  Restore the screen
  279. // mode on return (caller is responsible for screen redraw).
  280. // Optionally execute a DOS command.
  281. void    ScreenClass::jumpdos (char *cmdline)
  282. {
  283.   union REGS regs;
  284.   regs.h.ah = 3;
  285.   regs.h.bh = 0;
  286.   int86 (0x10,®s,®s);
  287.   savex = regs.h.dl;
  288.   savey = regs.h.dh;
  289.   saveshape = regs.x.cx;
  290.   textattr (oldattr);
  291.   HideMouse ();
  292.   clrscr ();
  293.   gotoxy (1,1);
  294.   shape (CUR